
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module table</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>table</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/media/sf_svns/occams/trunk/knife/table.py">/media/sf_svns/occams/trunk/knife/table.py</a></font></td></tr></table>
    <p><tt>A&nbsp;table&nbsp;is&nbsp;'meta'&nbsp;knowledge&nbsp;about&nbsp;some&nbsp;'data'.&nbsp;All&nbsp;rows<br>
of&nbsp;the&nbsp;'data'&nbsp;are&nbsp;the&nbsp;same&nbsp;size&nbsp;and&nbsp;the&nbsp;i-th&nbsp;column<br>
is&nbsp;described&nbsp;by&nbsp;the&nbsp;i-th&nbsp;item&nbsp;in&nbsp;'meta'.<br>
&nbsp;<br>
This&nbsp;code&nbsp;assumes&nbsp;that&nbsp;each&nbsp;row&nbsp;one&nbsp;'klass'&nbsp;value&nbsp;stored<br>
in&nbsp;the&nbsp;last&nbsp;item&nbsp;on&nbsp;each&nbsp;row.<br>
&nbsp;<br>
This&nbsp;code&nbsp;is&nbsp;part&nbsp;of&nbsp;KNIFE:&nbsp;cropping&nbsp;complexity,&nbsp;culling&nbsp;confusion,&nbsp;<br>
and&nbsp;cutting&nbsp;the&nbsp;crap&nbsp;since&nbsp;2012<br>
&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.----------------._________________<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|=()=========---&nbsp;&nbsp;\-----------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`\&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jgs&nbsp;&nbsp;\_________________/^^^^^^^^^^^^^^^^^^<br>
&nbsp;<br>
(c)&nbsp;2012,&nbsp;Tim&nbsp;Menzies,&nbsp;tim@menzies.us,&nbsp;LGPL&nbsp;v3.0<br>
&nbsp;<br>
Todo<br>
----<br>
Support&nbsp;multiple&nbsp;classes&nbsp;from&nbsp;any&nbsp;column.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="math.html">math</a><br>
</td><td width="25%" valign=top><a href="re.html">re</a><br>
</td><td width="25%" valign=top><a href="sys.html">sys</a><br>
</td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="table.html#Table">Table</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="Table">class <strong>Table</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr><td bgcolor="#ffc8d8"><tt>&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="Table-__init__"><strong>__init__</strong></a>(self)</dt><dd><tt>'Data'&nbsp;stores&nbsp;rows&nbsp;of&nbsp;data.&nbsp;The&nbsp;distances&nbsp;between&nbsp;<br>
rows&nbsp;is&nbsp;cached&nbsp;in&nbsp;'dists'.&nbsp;And&nbsp;'meta'&nbsp;stores&nbsp;what<br>
we&nbsp;know&nbsp;about&nbsp;each&nbsp;column.</tt></dd></dl>

<dl><dt><a name="Table-body"><strong>body</strong></a>(self, row, cells)</dt><dd><tt>Imports&nbsp;the&nbsp;'row'-th&nbsp;set&nbsp;of&nbsp;cells.&nbsp;Cells&nbsp;contents&nbsp;are<br>
converted&nbsp;to&nbsp;their&nbsp;right&nbsp;type&nbsp;by&nbsp;the&nbsp;'keep'&nbsp;function.</tt></dd></dl>

<dl><dt><a name="Table-clone"><strong>clone</strong></a>(self, data<font color="#909090">=[]</font>)</dt><dd><tt>Returns&nbsp;a&nbsp;new&nbsp;table&nbsp;with&nbsp;the&nbsp;same&nbsp;column&nbsp;names&nbsp;and&nbsp;types<br>
as&nbsp;the&nbsp;current&nbsp;table,&nbsp;but&nbsp;with&nbsp;diffent&nbsp;rows&nbsp;(read&nbsp;in&nbsp;from<br>
'data'.</tt></dd></dl>

<dl><dt><a name="Table-dist"><strong>dist</strong></a>(self, r1, r2)</dt><dd><tt>Return&nbsp;the&nbsp;distance&nbsp;between&nbsp;two&nbsp;rows&nbsp;of&nbsp;index&nbsp;'r1'&nbsp;and&nbsp;'r2'<br>
in&nbsp;data.&nbsp;For&nbsp;effeciecny&nbsp;reasons,&nbsp;results&nbsp;cached&nbsp;in&nbsp;'dists'.</tt></dd></dl>

<dl><dt><a name="Table-dist1"><strong>dist1</strong></a>(self, cells1, cells2)</dt><dd><tt>Primitive&nbsp;distance&nbsp;measure&nbsp;between&nbsp;2&nbsp;sets&nbsp;of&nbsp;cells.<br>
Implements&nbsp;Aha's&nbsp;1991&nbsp;distance&nbsp;measure:&nbsp;same&nbsp;things<br>
get&nbsp;distance&nbsp;'0',&nbsp;different&nbsp;symbols&nbsp;get&nbsp;distance&nbsp;'0'.<br>
If&nbsp;any&nbsp;missing&nbsp;values,&nbsp;then&nbsp;the&nbsp;max&nbsp;possible&nbsp;distance&nbsp;is<br>
returns.&nbsp;Returns&nbsp;a&nbsp;value&nbsp;0..1.</tt></dd></dl>

<dl><dt><a name="Table-header"><strong>header</strong></a>(self, n, str)</dt><dd><tt>Peeks&nbsp;at&nbsp;a&nbsp;header&nbsp;name&nbsp;and&nbsp;returns&nbsp;the&nbsp;right&nbsp;column&nbsp;type.</tt></dd></dl>

<dl><dt><a name="Table-headers"><strong>headers</strong></a>(self, cells)</dt><dd><tt>Calls&nbsp;'<a href="#Table-header">header</a>()'&nbsp;for&nbsp;'cells'&nbsp;(which&nbsp;is&nbsp;a&nbsp;list&nbsp;of&nbsp;text&nbsp;strings).</tt></dd></dl>

<dl><dt><a name="Table-median"><strong>median</strong></a>(self, what<font color="#909090">=&lt;function &lt;lambda&gt;&gt;</font>)</dt><dd><tt>Returns&nbsp;the&nbsp;median&nbsp;of&nbsp;a&nbsp;set&nbsp;of&nbsp;values&nbsp;computed&nbsp;from&nbsp;all&nbsp;rows.</tt></dd></dl>

<dl><dt><a name="Table-nearest"><strong>nearest</strong></a>(self, cells1)</dt><dd><tt>Returns&nbsp;the&nbsp;row&nbsp;nearest&nbsp;'cells1'&nbsp;(a&nbsp;list&nbsp;of&nbsp;cells).</tt></dd></dl>

<dl><dt><a name="Table-outmost"><strong>outmost</strong></a>(self, r1)</dt><dd><tt>Returns&nbsp;the&nbsp;row,&nbsp;and&nbsp;its&nbsp;distance,&nbsp;to&nbsp;data[r1].</tt></dd></dl>

<dl><dt><a name="Table-outmost2"><strong>outmost2</strong></a>(self)</dt><dd><tt>Returns&nbsp;the&nbsp;two&nbsp;most&nbsp;distant&nbsp;points&nbsp;in&nbsp;O(N^2)&nbsp;time.</tt></dd></dl>

<dl><dt><a name="Table-slurp"><strong>slurp</strong></a>(self, file)</dt><dd><tt>Reads&nbsp;data&nbsp;from&nbsp;a&nbsp;csv&nbsp;file.&nbsp;Assumes&nbsp;the&nbsp;first&nbsp;line&nbsp;<br>
has&nbsp;column&nbsp;names&nbsp;with&nbsp;'$'&nbsp;denoting&nbsp;numbers&nbsp;and&nbsp;'!'<br>
denoting&nbsp;class&nbsp;variables.&nbsp;Also,&nbsp;names&nbsp;can&nbsp;(optionally)<br>
be&nbsp;followed&nbsp;by&nbsp;'*N'&nbsp;which&nbsp;sets&nbsp;the&nbsp;weight&nbsp;of&nbsp;this<br>
column.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
    
<tr><td bgcolor="#eeaa77"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl><dt><a name="-leaveOneOut"><strong>leaveOneOut</strong></a>(file)</dt><dd><tt>For&nbsp;each&nbsp;row&nbsp;of&nbsp;data,&nbsp;build&nbsp;a&nbsp;table&nbsp;on&nbsp;the<br>
other&nbsp;rows.&nbsp;Retuns&nbsp;that&nbsp;row,&nbsp;the&nbsp;klass&nbsp;of&nbsp;that<br>
row,&nbsp;and&nbsp;the&nbsp;table&nbsp;generated&nbsp;from&nbsp;the&nbsp;other&nbsp;data.</tt></dd></dl>
</td></tr></table>
</body></html>